import cv2
from base_camera import BaseCamera

# RTSP地址
rtsp_url = "rtmp://81.71.160.25:8972/hls/123"


class Camera(BaseCamera):
    video_source = 0

    @staticmethod
    def set_video_source(source):
        Camera.video_source = source

    @staticmethod
    def frames():
        camera = cv2.VideoCapture(rtsp_url)
        if not camera.isOpened():
            raise RuntimeError('Could not start camera.')

        while True:
            # read current frame
            _, img = camera.read()
            try:

                # encode as a jpeg image and return it
                yield cv2.imencode('.jpg', img,[int(cv2.IMWRITE_JPEG_QUALITY), 10])[1].tobytes()
            except:
                pass